package de.jmda.gen.java;

import javax.lang.model.element.Modifier;

import de.jmda.gen.GeneratorException;

public abstract class ModifiersUtil
{
	public final static String PUBLIC       = Modifier.PUBLIC.toString();
	public final static String PROTECTED    = Modifier.PROTECTED.toString();
	public final static String PRIVATE      = Modifier.PRIVATE.toString();
	public final static String ABSTRACT     = Modifier.ABSTRACT.toString();
	public final static String FINAL        = Modifier.FINAL.toString();
	public final static String NATIVE       = Modifier.NATIVE.toString();
	public final static String STATIC       = Modifier.STATIC.toString();
	public final static String STRICTFP     = Modifier.STRICTFP.toString();
	public final static String SYNCHRONIZED = Modifier.SYNCHRONIZED.toString();
	public final static String TRANSIENT    = Modifier.TRANSIENT.toString();
	public final static String VOLATILE     = Modifier.VOLATILE.toString();

	// static final modifiers
	public final static String PUBLIC_STATIC_FINAL    = PUBLIC    + " " + STATIC + " " + FINAL;
	public final static String PROTECTED_STATIC_FINAL = PROTECTED + " " + STATIC + " " + FINAL;
	public final static String PRIVATE_STATIC_FINAL   = PRIVATE   + " " + STATIC + " " + FINAL;

	// final modifiers
	public final static String PUBLIC_FINAL    = PUBLIC    + " " + FINAL;
	public final static String PROTECTED_FINAL = PROTECTED + " " + FINAL;
	public final static String PRIVATE_FINAL   = PRIVATE   + " " + FINAL;

	// static non-final modifiers
	public final static String PUBLIC_STATIC    = PUBLIC    + " " + STATIC;
	public final static String PROTECTED_STATIC = PROTECTED + " " + STATIC;
	public final static String PRIVATE_STATIC   = PRIVATE   + " " + STATIC;
	
	public enum VisibilityModifier
	{
		// static final modifiers
		PUBLIC(   ModifiersUtil.PUBLIC),
		PROTECTED(ModifiersUtil.PROTECTED),
		PRIVATE(  ModifiersUtil.PRIVATE),
		DEFAULT("")
		;
		
		private String modifier;
		
		private VisibilityModifier(String modifier)
		{
			this.modifier = modifier;
		}

		@Override
    public String toString()
    {
	    return modifier;
    }
	}
	
	public enum StaticFieldDeclarationModifiers
	{
		// static final modifiers
		PUBLIC_STATIC_FINAL(   ModifiersUtil.PUBLIC_STATIC_FINAL),
		PROTECTED_STATIC_FINAL(ModifiersUtil.PROTECTED_STATIC_FINAL),
		PRIVATE_STATIC_FINAL(  ModifiersUtil.PRIVATE_STATIC_FINAL),
		
		// static non-final modifiers
		PUBLIC_STATIC(         ModifiersUtil.PUBLIC_STATIC),
		PROTECTED_STATIC(      ModifiersUtil.PROTECTED_STATIC),
		PRIVATE_STATIC(        ModifiersUtil.PRIVATE_STATIC),
		
		// just static modifier
		STATIC(                ModifiersUtil.STATIC)
		;
		
		private String modifiers;
		
		private StaticFieldDeclarationModifiers(String modifiers)
		{
			this.modifiers = modifiers;
		}

		@Override
    public String toString()
    {
	    return modifiers;
    }
	}
	
	public enum InstanceFieldDeclarationModifiers
	{
		// final modifiers
		PUBLIC_FINAL(   ModifiersUtil.PUBLIC_FINAL),
		PROTECTED_FINAL(ModifiersUtil.PROTECTED_FINAL),
		PRIVATE_FINAL(  ModifiersUtil.PRIVATE_FINAL),
		
		// non-final modifiers
		PUBLIC(         ModifiersUtil.PUBLIC),
		PROTECTED(      ModifiersUtil.PROTECTED),
		PRIVATE(        ModifiersUtil.PRIVATE),
		
		// just static modifier
		STATIC(         ModifiersUtil.STATIC)
		;
		
		private String modifiers;
		
		private InstanceFieldDeclarationModifiers(String modifiers)
		{
			this.modifiers = modifiers;
		}

		@Override
    public String toString()
    {
	    return modifiers;
    }
	}
	
	public final static boolean hasStaticModifier(StringBuffer stringBuffer)
			throws GeneratorException
	{
		if (stringBuffer.indexOf(ModifiersUtil.STATIC) >= 0)
		{
			return true;
		}
		
		return false;
	}
	
	public final static boolean hasAbstractModifier(StringBuffer stringBuffer)
			throws GeneratorException
	{
		if (stringBuffer.indexOf(ModifiersUtil.ABSTRACT) >= 0)
		{
			return true;
		}
		
		return false;
	}
}